<?php

require_once($_SERVER['DOCUMENT_ROOT'].'/ukkepuk/source/php/classes/service/CalendarService.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/ukkepuk/source/php/classes/utils/CalendarUtils.php'); 
	

$month = CalendarUtils::getThisMonth();
$year = CalendarUtils::getThisYear();
$day = CalendarUtils::getThisDay();


$prevdatekey = date("Ymd", mktime(0,0,0,$month, $day-7, $year));
$nextdatekey = date("Ymd", mktime(0,0,0,$month, $day+7, $year));

 $monthbeginweek = date("m", mktime(0,0,0,$month, $day-7, $year));



   $calendarService = new CalendarService();
   
   $kids;
   $calendarInfo = $calendarService->readKidsCommingThisWeek();
   
   foreach($calendarInfo as $calendarKids){
       
       foreach($calendarKids->getKids() as $kid){
           $kids[$kid->getName() . " " . $kid->getFirstName()][$calendarKids->getDate()] = $kid->getStartTime() . "-" . $kid->getEndTime();
       } 
   }
   
   //echo array_shift(array_values($calendarInfo));
   
   $weekIndex = date("N", mktime(0, 0, 0, $month, $day, $year));
   $thisBeginWeek = date("d", mktime(0,0,0, $month, $day-$weekIndex+1, $year));
        
   
   echo "<div class=\"kidattendance\">";
   echo "<span class=\"monthlabel\">Week van maandag " . $thisBeginWeek . " " . CalendarUtils::getMonthLabel($monthbeginweek) . "</span>";
   echo "<table class=\"kidsweek\"><tr><th>naam</th>";
   //generate header line
   foreach($calendarInfo as $calendarKids){
         echo "<th>". substr($calendarKids->getDate(), 6) . "</th>";
   }
   echo "</tr>";
   
  foreach(array_keys($kids) as $key){
     echo "<tr><td class=\"name\">$key</td>";
     foreach($calendarInfo as $calendarKids){
         if(isset($kids[$key][$calendarKids->getDate()])){
             echo "<td class=\"in\">van: <br/> tot: </td>";
         }
         else
             echo "<td></td>";
     }
     echo "</tr>";
       
   }
   
   echo "</table>";
    
  
   
?>

    <div class="actions">
        <?php
            echo "<img src=\"/ukkepuk/webcontent/images/right.png\" id=\"prevweek\" alt=\"print\" onclick=\"readKidsCommingInWeek('$nextdatekey')\"/>";
            echo "<img src=\"/ukkepuk/webcontent/images/left.png\"  id=\"nextweek\" alt=\"print\" onclick=\"readKidsCommingInWeek('$prevdatekey')\"/>";
        ?>
            <img src="/ukkepuk/webcontent/images/print.png" id="printbtn" alt="print" onclick="window.print()"/>
        
        
    </div>
</div>